package com.xln.furns.web;

import com.xln.furns.entity.Furn;
import com.xln.furns.entity.Page;
import com.xln.furns.service.FurnService;
import com.xln.furns.service.impl.FurnServiceimpl;
import com.xln.furns.utils.DateUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;

public class CustomerServlet extends BasicServlet {
    FurnService furnService = new FurnServiceimpl();

    protected void page(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int pageNo = DateUtils.parseInt(request.getParameter("pageNo"), 1);
        int pageSize = DateUtils.parseInt(request.getParameter("pageSize"), 4);
        Page<Furn> page = furnService.page(pageNo, pageSize);
        request.setAttribute("page", page);
        request.getRequestDispatcher("/customer/index.jsp").forward(request, response);
//        System.out.printf("page:"+page);

    }
    protected void pageByname(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int pageNo = DateUtils.parseInt(request.getParameter("pageNo"), 1);
        int pageSize = DateUtils.parseInt(request.getParameter("pageSize"), 4);
        String name = request.getParameter("name");
        if (null == name){
            name = "";
        }

        Page<Furn> page = furnService.pageByname(pageNo,pageSize,name);
        StringBuilder url = new StringBuilder("customerServlet?action=pageByname");
        if (!"".equals(name)){
            url.append("&name="+name);
        }
        page.setUrl(url.toString());
        request.setAttribute("page", page);
        request.getRequestDispatcher("/customer/index.jsp").forward(request, response);
//        System.out.printf("page:"+page);

    }
}